gdk: Add gdk_rectangle_contains_point() call
authorCarlos Garnacho <carlosg@gnome.org>
Fri, 12 May 2017 09:46:33 +0000 (11:46 +0200)
committerCarlos Garnacho <carlosg@gnome.org>
Thu, 25 May 2017 14:25:58 +0000 (16:25 +0200)
A little helper function for a somewhat common operation.

docs/reference/gdk/gdk4-sections.txt
gdk/gdkrectangle.c
gdk/gdkrectangle.h

index 25891c8d3bf280b5a2cac80d0739905488f98df4..2f6009261319eff47ac672f4ab42fe194d294337 100644 (file)
@@ -534,6 +534,7 @@ GdkRectangle
 gdk_rectangle_intersect
 gdk_rectangle_union
 gdk_rectangle_equal
+gdk_rectangle_contains_point
 
 <SUBSECTION Private>
 gdk_rectangle_get_type
index 491de6c1e5f8115242ac536da8f2f5adeafe7d4d..6e6fa61eb20e918245494ff646ebaa71e9d154a4 100644 (file)
@@ -136,6 +136,31 @@ gdk_rectangle_intersect (const GdkRectangle *src1,
   return return_val;
 }
 
+/**
+ * gdk_rectangle_contains_point:
+ * @rect: a #GdkRectangle
+ * @x: X coordinate
+ * @y: Y coordinate
+ *
+ * Returns #TRUE if @rect contains the point described by @x and @y.
+ *
+ * Returns: #TRUE if @rect contains the point
+ *
+ * Since: 3.90
+ **/
+gboolean
+gdk_rectangle_contains_point (const GdkRectangle *rect,
+                              int                 x,
+                              int                 y)
+{
+  g_return_val_if_fail (rect != NULL, FALSE);
+
+  return x >= rect->x &&
+    x < rect->x + rect->width &&
+    y >= rect->y &&
+    y < rect->y + rect->height;
+}
+
 /**
  * gdk_rectangle_equal:
  * @rect1: a #GdkRectangle
index 7c0252ff0b2426a1225fa50af812929849e9dbfb..225f048f593b10b488da22974cae46078a430c0c 100644 (file)
@@ -49,6 +49,11 @@ GDK_AVAILABLE_IN_3_20
 gboolean gdk_rectangle_equal     (const GdkRectangle *rect1,
                                   const GdkRectangle *rect2);
 
+GDK_AVAILABLE_IN_3_90
+gboolean gdk_rectangle_contains_point (const GdkRectangle *rect,
+                                       int                 x,
+                                       int                 y);
+
 GDK_AVAILABLE_IN_ALL
 GType gdk_rectangle_get_type (void) G_GNUC_CONST;